<?php
    require_once("lib/includes.php");

    $action = new Action();

    echo json_encode(
        $action->Invoke(function(JSONReply $reply)
        {

            $prefix = '%' . $_POST['prefix'] . '%';

            DB::Connect();

            $query = "SELECT ObjectID, Name FROM Objects WHERE Name LIKE '" . $prefix . "'";
            $stmt = DB::Query($query);

            $results = array();

            while ($row = $stmt->fetch_assoc())
            {
                $item = array
                (
                    "ObjectId" => $row['ObjectID'],
                    "Name" => $row['Name']
                );

                array_push($results, $item);
            }

            $stmt->close();

            DB::Disconnect();

            $reply->SetData($results);
        }));
?>